<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>refs</title>
  </head>

  <body>
    <!--  -->
    <!-- 准备好一个“容器” -->
    <div id="test"></div>
    <div id="test2"></div>

    <!-- 引入react核心库 -->
    <script type="text/javascript" src="js/react.development.js"></script>
    <!-- 引入react-dom，用于支持react操作DOM -->
    <script type="text/javascript" src="js/react-dom.development.js"></script>
    <!-- 引入babel，用于将jsx转为js -->
    <script type="text/javascript" src="js/babel.min.js"></script>
    <!-- <script src="./change_weather.js"></script> -->
  </body>
  <script src="./js/prop-types.js"></script>
  <script type="text/babel">
    class Runner extends React.Component {
      constructor(props) {
        super(props);
        this.state = { isHot: true };
      }
      showData = () => {
        const { btnRef } = this;
        console.log(btnRef, "showdata");
      };
      changeWeather = () => {
        //   不能这么写
        //   isHot=!isHot
        // 只要是方法就要获取一下state的值
        const { isHot } = this.state;
        this.setState({ isHot: !isHot });
      };
      saveBtnRef = (curNode) => {
        //   无论如何切换，也不调用
        const { isHot } = this.state;
        this.setState({ isHot: !isHot });
        console.log(curNode);
        this.btnRef2 = curNode;
        console.log("saveFn", curNode);
      };
      render() {
        console.log("btnref", this.btnRef); //undefined
        const { isHot } = this.state;
        return (
          <div>
            {/*改变一次state，会执行下面两次.第一个节点为Null，第二个是真实节点*/}
            {/* <button
              onClick={this.changeWeather}
              ref={(curNode) => {
                this.btnRef = curNode;
                console.log("ref53", curNode);
              }}
            >
              按钮啊啊啊啊啊
            </button> */}
            <br />
            <br />
            <button ref={this.saveBtnRef} onClick={this.changeWeather}>
              按钮二
            </button>
            <p>今天天气很{isHot ? "炎热" : "凉爽"}</p>
          </div>
        );
      }
    }
    ReactDOM.render(<Runner />, document.getElementById("test"));
  </script>
</html>
